# -*- coding: utf-8 -*-
from ssc.items import QQItem
import scrapy, json, logging


class QQSpider(scrapy.Spider):
    name = 'qq'
    start_urls = ['http://cgi.im.qq.com/cgi-bin/minute_city']

    def parse(self, response):
        try:

            res = json.loads(response.body)

            item = QQItem()
            item['qq_time'] = res.get('time', '')
            item['qq_arr'] = res.get('minute', [])
            yield item

            #ww = 'QQ人数：{}：{}\n'.format(item['qq_time'], item['qq_value'])

            #with open('a.json', 'a') as f:
            #    f.write(ww)

        except Exception as err:
            logging.info(err)
